package yang.VirtualMachine.chapter11.javaagent1;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.sun.tools.attach.AgentInitializationException;
import com.sun.tools.attach.AgentLoadException;
import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;

public class AttachToolMain {

	public static void main(String[] args) throws AttachNotSupportedException, IOException, AgentLoadException, AgentInitializationException {
		List<VirtualMachineDescriptor> list = VirtualMachine.list();
		for (VirtualMachineDescriptor vmd: list) {
			System.out.println(vmd.displayName());
			if (vmd.displayName().endsWith("RunLoopAccountMain")) {
				VirtualMachine m = VirtualMachine.attach(vmd.id());
				m.loadAgent("D:\\a.jar", "args heheda");
				System.out.println("ok");
				m.detach();
			}
		}
	}

}
